 /**
  * 显示合同列表
  */
 var tjstate =0;
 function chanagestate(){
	 tjstate =0;
 }
  function showconpage(obj){
	  parent.showiframepage({"checked":1,"children":[],"createdate":"","endsize":0,"href":"/customer/intocontractlist","icon":"fa-navbar0","id":15,"isCurrent":1,"pagerFlag":0,"pid":2,"rows":0,"rowsCount":0,"spread":1,"timeLine":"","title":"合同管理","totalResults":0,"updatedate":""});
	  tjstate= 1;
  }

  function cb_callout(obj){
	  
	  //alert(obj)
  }
  
    layui.use(['icheck','element',"laytpl",'laypage','form','laydate'], function() {
        var $ = layui.jquery,
        layer = layui.layer,
        laytpl = layui.laytpl,
        laypage = layui.laypage;
        var form = layui.form();
       
        var jobselobj=   $("#zizhiType").jobsel({
           	'inputName' : "category"
           });
        jobselobj.init();
      
        $(".icon-im_dianhua1").on("click",function(){
        	
        	if(callcenterstate==0){
        		layer.msg('请开通轻客呼叫中心' );
        		return false;
			}
        	var tel =$(this).attr("data");
        	 tel = tel.replace(";","").replace(" ","");
        	var cusid =$(this).attr("dataid"); 
        	var lxdataid =$(this).attr("lxdataid");
        	var tr = $(this).parent().parent();
        	var lxr = tr.find("#dhlxr").text();
        	var 	 html ="<option value='"+lxdataid+"'>"+lxr.replace("\n","").replace("\r","").replace(" ","")+"(电话："+tel+")</option>";
        	$("#contact").html(html);
	 			form.render(); 
	 			 layer.open({
                    type:1,
                    content:$('.addlxjl'),
                    btn:['确定','取消'],
                    btnAlign:'c',
                    shadeClose:false,
                    title:'添加联系记录',
                    area:['600px','300px'],
                    maxWidth:800,
                    yes: function(layero, index){
	                   		var ccuid = $("#contact").val();
	                       	var remark = $("#remark").val();
	                       	var type = $("#customertype").val();
	                       	var state = $("#customerstate").val();
	                       	var pageNo = $("#pageNo").val();
	                       	var url = "/customer/entman/ty"+type+"_st"+state+"_p"+pageNo;
	                       	$.ajax({
	                       		type : "post",
	                       		url : "/customer/addcontactsdynamicinfo",
	                       		data : {ccuid:ccuid,remark:remark,cusid:cusid},
	                       		dataType : "json",
	                       		success : function(data){
	                       			if (data == 1) {
	                       				layer.closeAll();
	                       				layer.msg("添加联系记录成功",{icon: 1},function(){
	                       					
	                       				});
	                       			} else { 
	                       				layer.msg("添加联系记录失败",{icon: 2});
	                       			}
	                       		}
	                       	});
                    }
               });
        	
        	
        	layer.confirm('请确认电话：'+tel, {
        		  btn: ['确认拨打'] //可以无限个按钮
        	      ,shade: 0
        		  ,btn1: function(index, layero){
        			 
        		   layer.msg('正在拨号，请勿关闭界面', {icon: 16},function(){
        			   layer.confirm('通话中：'+tel, {
        				   anim:2,
        				   offset: 't',
        	        		  btn: [ '挂断'] //可以无限个按钮
        	        	      ,shade: 0
        	        		  ,btn1: function(index, layero){
        	        			  
        	        			  layer.msg('正在挂断电话...', {icon: 16},function(){});
        	        			  /*var status =  localStorage.getItem('workbenchSdkStatus');
        	        			  if(status>=8&&status<=12){
        	        				    localStorage.setItem('workbenchSdkHangup', Math.random())
        	        			  } */
        	        			  
        	        			  $.ajax({
        	               			type : "get",
        	               			url : "http://127.0.0.1:3366/callhang?callback=cb_callout",
        	               			async:false,
        	               			dataType : "html",
        	               			success : function(data){
        	               				result = data;
        	               				//eval(result); 
        	               				 
        	               			}
        	               		}); 
        	        			   
        	        				 
        	        		  }
        			   }); 
        		   });
        		   
        		   
        			 var telurl ="http://127.0.0.1:3366/callout?phone="+tel+"&callback=cb_callout&recordId="+cusid+"-"+currentuserid;
     				$.ajax({
             			type : "get",
             			url : telurl,
             			async:false,
             			dataType : "html",
             			success : function(data){
             				result = data;
             				//eval(result); 
             			}
             		}); 
        		 
        			  
        			/*  var status =  localStorage.getItem('workbenchSdkStatus');
        			  if(status==3||status==4||status==5){
        				  	  var value = {'callee':tel, 'random': Math.random()};
     		        	      localStorage.setItem('workbenchSdkCall', JSON.stringify(value)); 
        			  } 
        			  */
    		      
    		     return false;
    		        	
    		        	 //$(".lxjlbtn").
        			  
        			 
        		  } 
        		}  );
        	 
        })
        
    
        
      //  
     /*   var jobselobj=   $("#zizhiType").jobsel({
           	'inputName' : "category"
           });
      
        jobselobj.init(); 
        
        var id = $("#province").val();
	   var html = city.getCityByPid(id);
	    $("#city").html(html);
	    var cv =  $("#city").attr("value"); 
	    if(cv>0){
		  $("#city").val(cv); 
	    }*/
	    //更新渲染  
	    form.render(); 
	    
	    var pageNo = $("#pageNo").val();
    	var totalPage = $("#totalPage").val();
    	
    	//分页按钮
    	laypage({
            cont: 'page',
            curr: pageNo//'${pager.pageNo}'
            ,pages: totalPage//'${pager.totalPages}' //总页数
            ,
            groups: 5 //连续显示分页数
            ,
            skip: true,
            jump: function(obj, first) {
                //得到了当前页，用于向服务端请求对应数据
                var curr = obj.curr;
                if(!first) {
                	$("#skipToPage").val(curr);
                	$("#customerlistform").submit();
                }
            }
        }); 
    	
    	 getZsUser = function (o){
    		 var result ="";
    		  var values = o;
    			$.ajax({
        			type : "post",
        			url : "/customer/userlist",
        			data : values,
        			async:false,
        			dataType : "json",
        			success : function(data){
        				result = data;
        				//layer.msg('资源获取到线索库成功', {icon: 1},function(){
       					// window.location.href=url;
    					// });
        			}
        		});
    	  	 return result
    	 }
    	 var rzjgtitle ="人才证书价格";
    	 var qyjgtitle ="企业证书价格";
    	 var zssl="备注";
    	 var rytitle="猎证";
    	 form.on('select(contracttype)', function(data){
    		    if(data.value==0){
    		       //资质合同	
    		    	 rzjgtitle ="成本价格";
    		    	 qyjgtitle ="代办价格";
    		    	 rytitle="资质";
    		    	 zssl="备注";
    		    }else  if(data.value==1){
    		    	//猎证合同 
    		    	 rzjgtitle ="人才证书价格";
    		    	 qyjgtitle ="企业证书价格";
    		    	 rytitle="猎证";
    		    	 zssl="备注";
    		    }else if (data.value==2){
    		    	//培训合同
    		    	 rzjgtitle ="单价";
    		    	 qyjgtitle ="总价";
    		    	 rytitle="培训";
    		    	 zssl="数量（本）";
    		    }
    		    $("#rzjgtitle").html(rzjgtitle);
		    	 $("#qyjgtitle").html(qyjgtitle);
		    	 $("#zssl").html(zssl);
		    	 $("#rytitle").html(rytitle);
    		});
    	 
    	 
    	 //合同表单
    	 $("#hetongform").validate({
         	rules: {
         	 
 	    		signingtime : {
 	    			required:true
 	    		},
 	    		totalamount : {
 	    			required:true,
 	    			digits:true
 	    		},
 	    		contracttype : {
 	    			required:true
 	    		},
 	    		lifetype : {
 	    			required:true
 	    		}
 	    	},
 	    	messages: {
 	    		 
 	    		signingtime : {
 	    			required:"请选择合同签订时间"
 	    		},
 	    		totalamount : {
 	    			required:"请填写合同金额",
 	    			digits:"请填写正确金额"
 	    		},
 	    		contracttype : {
 	    			required:"请选择合同类型"
 	    		},
 	    		lifetype : {
 	    			required:"请选择合同签订年限"
 	    		}
 	    	},
 	    	errorPlacement: function(error, element) {
 				layer.tips(error.text(), element, {
 					tips: [2,tipColor],
 	     		 tipsMore: true
 	     		});
 	   		}, 
	 	   	 submitHandler: function(formobj) { 
	 	     	
           		  if(validatezstj()){
           		 
           			var values = $("#hetongform").serialize()
           			$.ajax({
         		 		type : "post",
         		 		url : "/customer/savecontract",
         		 		data : values,
         		 		dataType : "json",
         		 		async : false,
         		 		success : function(data){
         		 			if(data==1){
         		 				layer.closeAll();
         		 				layer.msg('合同申请成功', {icon: 1});
         		 				layer.confirm('继续添加回款信息?', function(index){
         		 				  //do something
         		 				  showconpage();
         		 				  layer.close(index);
         		 				});    
         		 				
         		 			   
         		 			}else{
         		 				layer.msg('合同申请失败', {icon: 2});
         		 			}
         		 		}
         		 	});
           			  
           		  }  
	 		      return  false;
	 	      }
         	
         });
    	 //验证证书相关条件 在这计算服务费用和合同总金额
    	 var validatezstj = function(){
    		 var result =true;
    		 var trs = $(".tb_zs tr");
    		 var resallcount = 0; //人才证书总价
    		 var cusallcount = 0; //企业证书总价
    		 var othallcount = 0; //其他价格总价
    		 
    		 if(trs.length<1){ //判断是否已添加证书
    			 layer.tips("请选择证书", $("#sxzs"), {
    				 tips: [1,tipColor],
    				 tipsMore: true
    			 });
    			 return false;
    		 }
    		 	
    		 var inputobj = trs.find("input[name=totalms]"); //人才
    		 var inputobj2 = trs.find("input[name=alonems]"); //企业
    		 var inputobj3 = trs.find("input[name=otmoney]"); //其他
    		 
    		 for(var i=0;i<inputobj.length;i++){
    			 //判断证书价格是否已填
    			 var val = $(inputobj[i]).val();
    			 if(val.length<1){
    				 layer.tips("请填写"+rzjgtitle, $(inputobj[i]), {
    					 tips: [2,tipColor],
    					 tipsMore: true
    				 });
    				 result = false;
    			 }else{
    				 var reg = /^[0-9]*$/;
    				 if (!reg.test(val)) { 
    					 layer.tips("价格请填写数字", $(inputobj[i]), {
    						 tips: [2,tipColor],
    						 tipsMore: true
    					 });
    					 result = false;
      				}else{
      					resallcount += parseInt(val);
      				}
      			}
      			
      		  }
      		for(var i=0;i<inputobj2.length;i++){
    			  //判断证书价格是否已填
    			var val = $(inputobj2[i]).val();
    			if(val.length<1){
    				 layer.tips("请填写"+rzjgtitle, $(inputobj2[i]), {
        				 tips: [2,tipColor],
	           	     		 tipsMore: true
	           	     	 });
    				result = false;
    			}else{
    				var reg = /^[0-9]*$/;
    				if (!reg.test(val)) { 
    					layer.tips("价格请填写数字", $(inputobj2[i]), {
           				 tips: [2,tipColor],
 	           	     		 tipsMore: true
 	           	     	 });
    					result = false;
    				} else {
    					cusallcount += parseInt(val);
    				}
    			} 
      		}
      		for (var i = 0;i < inputobj3.length;i ++) {
      			var val = $(inputobj3[i]).val();
      			var reg = /^[0-9]*$/;
      			if (!reg.test(val)) {
      				layer.tips("价格请填写数字", $(inputobj2[i]),{
      					tips: [2,tipColor],
      					tipsMore: true
      				});
      				result = false;
      			} else if (val.length > 0) {
      				othallcount += parseInt(val);
      			}
      		}
      		
  			if(cusallcount<(resallcount+othallcount)){
  				layer.tips(rzjgtitle+"不能大于"+qyjgtitle, $("#sxzs"), {
  					tips: [1,tipColor],
  					tipsMore: true
  				});
  				result = false;
  			}else{
  				//服务费用=企业-人才-其他
  				$("#servicecharge").val(cusallcount-resallcount-othallcount);
  				//合同总价=企业
  				$("#totalamount").val(cusallcount);
  			}
      		return result;
    	 }
    	 
    	 
    	 $(document).on("blur","input[name=alonems]",function(){
    		 validatezstj();
    	 })
    	 $(document).on("blur","input[name=totalms]",function(){
    		 validatezstj();
    	 })
     	//申请合同按钮
     	$(".sqhtbtn").on("click",function(){
     		tjstate =0;
     		//重置表单
     		document.getElementById("hetongform").reset();
     		$(".tb_zs").html("")
     		var size = $("input:checkbox[name='customcheckbox']:checked").length;
     		if(size!=1){
     			layer.msg("请选择一条企业记录",{icon: 0});
 				 return false;
     		}
     		var id = $("input:checkbox[name='customcheckbox']:checked").val(),
     		    qyname = $("input:checkbox[name='customcheckbox']:checked").attr("dname");
     		$(".htqyname").text(qyname);
     		$("#qyid").val(id);
     		var childFrame= null;
     		layer.open({
	  			  type: 2, 
	  			  title:qyname+'的合同',
	  			  area: ['95%', '95%'],
	  			  content: "/customer/contracttemplate?type=1&cusid="+id, 
	  			 btn: ['提交合同', '取消'],
	  			 scrollbar:true,
                 btnAlign:'c',
                 yes: function(){
                	 if(tjstate==0){
                		 childFrame.submitForm();
                		 tjstate=1;
                	 }else{
                		 layer.msg("正在提交合同,请勿重复提交",{icon: 0});
                	 }
                
                 
                  },success:function(layero, index){
                	   //var body = layer.getChildFrame('body', index);
                	    var iframeWin = window[layero.find('iframe')[0]['name']]; //得到iframe页的窗口对象，执行iframe页的方法：iframeWin.method();
                	   // console.log(body.html()) //得到iframe页的body内容
                	    childFrame = iframeWin;
                	   
                  }
	  		 }); 
     		
     	/*	 layer.open({
                  title:'申请合同',
                  type:1, 
                  content:$('#TM-layui-hetong'),
                  btn: ['提交合同', '取消'],
                  shadeClose:true,
                  scrollbar:true,
                  btnAlign:'c',
                  area: ['99%','99%'],
                  yes: function(){
                	 if(tjstate ==0){
                	   if(validatezstj()){
                		   $("#hetongform").submit();
                	   } 
                	 }else{
                		 layer.msg("正在提交合同,请勿重复提交",{icon: 0});
                	 }
                  },
     		   success: function(layero, index){
     			  tjstate =0;
     		  }
              });*/
     	});
     	 var zspop = "";
     	 //添加证书
          $('.zhengshu').on('click',function(){
        	  zspop = layer.open({
           		title:'添加证书',
           	 	type:1,
           	 	id:"tjzs",
              	  	shadeClose: true,
              	  	content:$('#TM-layui-zhengshu'),
                   btnAlign:'c',
                   area:['90%','95%']
              	}); 
           }); 
    	 
    	 //证书添加
    	 $(document).on('click','.addzs',function(){
    		  var result = eval('(' + $(this).attr("data") + ')') ,
    		  getTpl = $("#zs").html();
    		  if($(".tb_zs  tr[data="+result.id+"]").length>0){
    			  layer.msg('请勿重复添加' ,{icon: 0});
    			  return false;
    		  }
    		  laytpl(getTpl).render(result, function(html){
 				 $(".tb_zs").append(html);
 				layer.close(zspop);
 					  //view.innerHTML = html;
 			  });
    	 });
    	 
    	 //证书删除
    	 $(document).on('click','.deletezs',function(){
    		var id = $(this).attr("data");
    		   layer.confirm('确定要删除该证书吗？', {
    			  btn: ['确定','取消'] //按钮
    			}, function(){
    			   $(".zs"+id).remove(); 
    			   layer.msg("删除成功",{icon:1 });
    			}, function(){}); 
    	 });
    	 //证书其它费用
    	 $(document).on('click','.addothermoney',function(){
    		var id = $(this).attr("data");
    		// $("#othermy"+id).show(); 
    		 $("#othermy"+id).toggle();
    		 $("#othermy"+id +"  input[name=otmoney]").val(0);
    	 });
    	 
    	//证书搜索
    	$(".zssearchbtn").on("click",function(){
    		var kd =  $.trim($("#zskeyword").val());
    		$("#skpg").val(1);
    		if(kd.length<1){
    			
    			layer.tips("请输入关键字", "#zskeyword", {
    				tips: [1,'#f7625e'], 
    				time:5000,
         		    tipsMore: false
         		});
    			return false;
    		}else{
    			$("#zskeyword").val(kd);
    		    var values = $("#zssearch").serialize()
    			var result = getZsUser(values);
    		    var getTpl = $("#zslb").html();
    		    
				 laytpl(getTpl).render(result, function(html){
				 $(".tb_customerzs").html(html);
					  //view.innerHTML = html;
				 });
    			 laypage({
                      cont: 'zspage',
                      curr: 1//'${pager.pageNo}'
                      ,pages: result.totalPages//'${pager.totalPages}' //总页数
                      ,
                      groups: 5 //连续显示分页数
                      ,
                      skip: true,
                      jump: function(obj, first) {
                          //得到了当前页，用于向服务端请求对应数据
                          var curr = obj.curr;
                          if(!first) {
                        	  $("#skpg").val(curr);
                        	   values = $("#zssearch").serialize()
                  			   result = getZsUser(values); 
                        	   var getTpl = $("#zslb").html();
                        	   laytpl(getTpl).render(result, function(html){ 
                					 $(".tb_customerzs").html(html); 
                			    }); 
                          }
                      }
                  });  
    		}
    	})
    	
    	$(".searchbtnclean").on("click",function(){
    		$("#keyWord").val("");
    		$("#province").val("");
    		$("#address").val("");
    		$("#city").html("<option value=\"\">请选择市</option>");
		    $("#city").val("");
		    $("#category").val("");
		    $("#zizhiType").val("");
    	});
    	
    	
    	
    	$("#keyWord").on("click",function(){
    		var text = "关键字在我的企业资源里包括：企业名称，企业联系人电话<br/>"
    			+ "关键字在我的人才资源里包括：人才名称，人才联系电话，人才身份证号<br/>";
    		layer.tips(text, "#keyWord", {
				tips: [1,'#f7625e'],
				area:["410px"],
				time:5000,
     		 tipsMore: true
     		});
    	});
    	$("#keyWord").on("blur",function(){
    		layer.closeAll();
    	})
    	
    	
	    
	    var statess = $("#customerstate").val();
	    if (statess != null && statess != "") {
	    	$("#states").val(statess);
	    	form.render(); 
	    }
	    
        
        //点击搜索
    	$(".customersearchbtn").on("click",function(){
    		var ky = $.trim($("#keyWord").val());
       	    $("#keyWord").val(ky);
       	    $("#skipToPage").val(1);
    		$(".customersearcheform").submit();
    	});
    	
    	//录入信息按钮
    	$(".lrxxbtn").on("click",function(){
    		var type = $("#customertype").val();
    		parent.layer.open({
  			  type: 2, 
  			  title:"录入信息",
  			  area: ['95%', '95%'],
  			  content: "/customer/addcustomer"+type, //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
  		 }); 
    		
    	});
    	
    	//点击修改
    	$(".xgbtn").on("click",function(){
    		var value = $(this).parent().attr("data");
    		var url = "/customer/updatecustomer"+value;
    		window.open(url);
    	});
    	
    	//获取按钮（多个）
    	$(".plhqbtn").on("click",function(){
    		
    		var id = $(this).attr("data");
    		var state = $("#customerstate").val();
    		var type = $("#customertype").val();
    		var url = "/customer/entman/ty"+type+"_st"+state+"_p"+pageNo;
    		
    		var value;
    		var i =0;
    		//利用.each获取
			$("input:checkbox[name='customcheckbox']:checked").each(function(i){
				if (i == 0) {
					value = $(this).val();
				} else {
					value += ","+$(this).val();
				}
				i++;
			});
			if (value == null || value == "") {
				 layer.msg("请选择一条或多条记录", {icon: 0});
				 return false;
			 }
			layer.confirm('确定获取选中的资源吗？', function(index){
				$.ajax({
					type : "post",
					url : "/customer/updatecustomerstate",
					data : {value:value,state:state,type:type,cname:i+"条记录"},
					dataType : "json",
					async: false,
					success : function(data){
						var msg = "";
	    				var icon = "";
	    				if (data == 0) {
	    					msg = "资源获取失败,请重试";
	    					icon = {icon: 5};
	    				} else if (data == -1) {
	    					msg = "资源获取失败,已达可获取上限,</br>请联系管理员更改上限";
	    					icon = {icon: 5};
	    				} else {
	    					msg = "已成功获取"+data+"条资源";
	    					icon = {icon: 1};
	    				}
	    				layer.msg(msg, icon,function(){
							//window.location.href=url;
							$(".customersearchbtn").click();
						});
					}
				});
				layer.close(index);
			});   
    	});
    	
    	
    	//获取按钮(单条)
    	$(".hqbtn").on("click",function(){
    		var id = $(this).attr("data");
    		var state = $("#customerstate").val();
    		var type = $("#customertype").val();
    		var cname = $(this).parent().parent().attr("cname");
    		//跳转地址 以后要是有其他参数了再加
    		var url = "/customer/entman/ty"+type+"_st"+state+"_p"+pageNo;
    		//获取跟升级一样的 就是把公共库的升级进线索库
    		$.ajax({
    			type : "post",
    			url : "/customer/updatecustomerstate",
    			data : {value : id , state : state ,type : type,cname:cname},
    			dataType : "json",
    			success : function(data){
    				
    				var msg = "";
    				var icon = "";
    				if (data == 0) {
    					msg = "资源获取失败,请重试";
    					icon = {icon: 5};
    				} else if (data == -1) {
    					msg = "资源获取失败,已达可获取上限,</br>请联系管理员更改上限";
    					icon = {icon: 5};
    				} else {
    					msg = "资源获取成功";
    					icon = {icon: 1};
    				}
    				layer.msg(msg, icon,function(){
						//window.location.href=url;
						$(".customersearchbtn").click();
					});
    			}
    		});
    	});
    	
    	//核对查询按钮
    	$(".hdcxbtn").on("click",function(){
    		var type = $("#customertype").val();
    		parent.layer.open({
    			  type: 2, 
    			  title:"核对查询",
    			  area: ['95%', '95%'],
    			  content: '/customer/checkcustomer'+type, //这里content是一个URL，如果你不想让iframe出现滚动条，你还可以content: ['http://sentsin.com', 'no']
    		 }); 
    	});
    	
    	//放弃按钮（多个）
    	$(".fqbtn").on("click",function(){
    		
    		var id = $(this).attr("data");
    		var state = $("#customerstate").val();
    		var type = $("#customertype").val();
    		var url = "/customer/entman/ty"+type+"_st"+state+"_p"+pageNo;
    		
    		var value;
    		//利用.each获取
			$("input:checkbox[name='customcheckbox']:checked").each(function(i){
				if (i == 0) {
					value = $(this).val();
				} else {
					value += ","+$(this).val();
				}
			});
			if (value == null || value == "") {
				 layer.msg("请选择一条或多条记录", {icon: 0});
				 return false;
			 }
			layer.confirm('确定放弃吗？', function(index){
				$.ajax({
					type : "post",
					url : "/customer/updatecustomerstateignore",
					data : {value:value,state:state,type:type},
					dataType : "json",
					async: false,
					success : function(data){
						if (data == 1) {
							layer.msg('放弃成功', {icon: 1},function(){
		   					 //	window.location.href=url;
		   					 $(".customersearchbtn").click();
							});
						} else {
							layer.msg('放弃失败', {icon: 2},function(){
		   					 	//window.location.href=url;
		   					   $(".customersearchbtn").click();
							});
						}
					}
				});
				layer.close(index);
			});   
    	});
    	
    	//放弃按钮（单个）
    	$(".fqbtn1").on("click",function(){
    		var id = $(this).attr("data");
    		var state = $("#customerstate").val();
    		var type = $("#customertype").val();
    		var url = "/customer/entman/ty"+type+"_st"+state+"_p"+pageNo;
    		
    		var value = $(this).parent().attr("data");
			if (value == null || value == "") {
				 layer.msg("请选择一条或多条记录",{icon: 0});
				 return false;
			 }
			layer.confirm('确定放弃吗？', function(index){
				$.ajax({
					type : "post",
					url : "/customer/updatecustomerstateignore",
					data : {value:value,state:state,type:type},
					dataType : "json",
					async: false,
					success : function(data){
						if (data == 1) {
							layer.msg('放弃成功', {icon: 1},function(){
		   					 	window.location.href=url;
							});
						} else if (data == 2) {
							layer.msg('该人才已关联合同，放弃失败,', {icon: 2},function(){
		   					 	window.location.href=url;
							});
						} else {
							layer.msg('放弃失败', {icon: 2},function(){
		   					 	window.location.href=url;
							});
						}
					}
				});
				layer.close(index);
			});  
    	});
    	
    	//添加预约按钮
    	$(".yysjbtn").on("click",function(){
    		var value;
    		//利用.each获取
			$("input:checkbox[name='customcheckbox']:checked").each(function(i){
				if (i == 0) {
					value = $(this).val();
				} else {
					value += ","+$(this).val();
				}
			});
			if (value == null || value == "") {
				 layer.msg("请选择一条或多条记录",{icon: 0});
				 return false;
			 }
			//然后就是打开弹窗
			layer.open({
      		  	type:1,
		  		title:"添加预约",
		  		zIndex: 999,
		  		//shadeClose:true,
		  		content: $("#TM-layui-bookingTo"),
		  		area:[500,600],
      		});
    	});
    	
    	//保存预约
    	$("#savebooking").on("click",function(){
    		
    		var value;
    		//利用.each获取
			$("input:checkbox[name='customcheckbox']:checked").each(function(i){
				if (i == 0) {
					value = $(this).val();
				} else {
					value += ","+$(this).val();
				}
			});
			
			var stime = $("#stime").val();
			var remark = $("#email-inner").val();
    		
			if (stime == null || stime == "") {
				layer.tips("请选择预约时间", $("#stime"), {
					tips: [2,tipColor],
	     		 tipsMore: true
	     		});
				return false;
			}
			
			$.ajax({
				type : "post",
				url : "/customer/bookingcontactsdynamicinfo",
				data : {stime:stime,remark:remark,value:value},
				dataType : "json",
				success : function(data){
					if (data == 0) {
						layer.msg("预约失败，请重试",{icon: 2},function(){
							layer.closeAll();
						});
					} else {
						layer.msg("预约成功",{icon: 1},function(){
							layer.closeAll();
						});
					}
				}
			});
    		
    	});
    	
    	//取消
    	$("#cancelbooking").on("click",function(){
    		layer.closeAll();
    	});
    	
    	
    	
    	//点击打开企业详情
    	$(".showinfo").on("click",function(){
    		var id = $(this).attr("data");
    		var url = "/customer/updatecustomer"+id;
    		window.open(url);
    	});
   
    	/**
    	 * 已联系，未联系和待预约
    	 * */
    	$(document).on("click",".lx_checkbox1",function(){
    		
    		var data = $(this).attr("data");
    		
    		if ($(this).is(":checked")) {
    			$("input[data='"+ data +"']").prop("checked",true);
    		} else {
    			$("input[data='"+ data +"']").prop("checked",false);
    		}
    		
    	});
    	
    	
    	
    	//全选，取消全选
    	$("#selected-all").on("click",function(){
			if ($("#selected-all").is(":checked")) {
				$("[name='customcheckbox']").prop("checked",true);
			} else {
				$("[name='customcheckbox']").prop("checked",false);
			}
		});
    	

    	
    	//申请合作按钮
    	/*$(".sqhzbtn").on("click",function(){
    		alert("点击了申请合作按钮");
    	});*/
    	
    	//省市选择
    	form.on('select(province)', function(data){
    		var id = $("#province").val();
    		var html = city.getCityByPid(id);
			$("#city").html(html);
			//更新渲染  
	    	form.render('select'); 
    	});
    	
    	//放入回收站
    	$(".hszbtn").on("click",function(){
    		 
    		var id = $(this).attr("data");
    		 layer.confirm('确定申请放入回收站吗？', {
   			  btn: ['确定','取消'] //按钮
   			}, function(){
   			   	$.ajax({
    				type : "post",
    				url : "/customer/recyclebinsave",
    				data : {cusid:id},
    				dataType : "json",
    				success : function(data){
    					if(data=="1"){
    						 layer.msg("申请放入回收站成功",{icon: 1},function(){
    							 var state = $("#customerstate").val();
    					    	 var type = $("#customertype").val();
    					    	 var url = "/customer/entman/ty"+type+"_st"+state+"_p"+pageNo;
    							 window.location.href=url;
        					});
    					}else{
    						layer.msg("申请放入回收站失败",{icon: 2} );
    					} 
    				}
    			});
   			}, function(){}); 
    	})
    	
    	//点击添加联系记录
    	$(".lxjlbtn").on("click",function(){
    		$("#remark").val("");
    		var id = $(this).attr("data");
      		$.ajax({
 		 		type : "post",
 		 		url : "/customer/customerinfoajax",
 		 		data : {id:id},
 		 		dataType : "json",
 		 		async : false,
 		 		success : function(data){
 		 			if (data != null) {
 		 				var html ="";
 	 		 		    var contacts =	data.contactsItem;
 	 		 		    var cname = data.cname; 
 	 		 		    if(contacts!=null&&contacts.length>0){
 	 		 		    	for(var i =0;i<contacts.length;i++){
 	 		 		    		 html+="<option value='"+contacts[i].id+"'>"+contacts[i].name+"(电话："+contacts[i].phone+")</option>";
 	 		 		    	} 
 	 		 		    	$("#contact").html(html);
 	 		 		    }else{
 	 		 		    	$("#contact").html("<option value=''>请选择联系人</option>");
 	 		 		    }
 	 		 			form.render(); 
 	 		 			 layer.open({
 		                       type:1,
 		                       content:$('.addlxjl'),
 		                       btn:['确定','取消'],
 		                       btnAlign:'c',
 		                       shadeClose:false,
 		                       title:cname+'添加联系记录',
 		                       area:['600px','300px'],
 		                       maxWidth:800,
 		                       yes: function(layero, index){
 			                   		var ccuid = $("#contact").val();
 			                       	var remark = $("#remark").val();
 			                       	var cusid = id;
 			                       	var type = $("#customertype").val();
 			                       	var state = $("#customerstate").val();
 			                       	var pageNo = $("#pageNo").val();
 			                       	var url = "/customer/entman/ty"+type+"_st"+state+"_p"+pageNo;
 			                       	$.ajax({
 			                       		type : "post",
 			                       		url : "/customer/addcontactsdynamicinfo",
 			                       		data : {ccuid:ccuid,remark:remark,cusid:cusid},
 			                       		dataType : "json",
 			                       		success : function(data){
 			                       			if (data == 1) {
 			                       				layer.closeAll();
 			                       				layer.msg("添加联系记录成功",{icon: 1},function(){
 			                       					
 			                       				});
 			                       			} else { 
 			                       				layer.msg("添加联系记录失败",{icon: 2});
 			                       			}
 			                       		}
 			                       	});
 		                       }
 	 	                 });
 		 			} else {
 		 				layer.msg("无权添加联系记录",{icon: 2})
 		 			}
 		 		}
 		 	});
    	});
    	
    	
    	//移上去查看联系方式
    	$(document).on("mouseover",".seenote",function(){
    		layer.closeAll();
    		var data = $(this).attr("data");
    		//layer.msg("测试一下"+data);
    		var ele = $(".seenote"+data);
    		$.ajax({
    			type : "post",
    			url : "/customer/customercontactsbycusid",
    			data : {id : data},
    			dataType : "json",
    			async: false,
    			contentType: "application/x-www-form-urlencoded; charset=utf-8",
    			success : function(data){
    				
    				var jsondata = eval(data);
    				var html = "";
    				if (jsondata.length > 0) {
    					$.each(data, function (i, item) {
        		        	html += "["+ item.updatedate.substring(0,10) +"]"+item.remark+"------"+item.uname+"<br/>";
        		        });
    				} else {
    					html = "该数据暂无联系记录";
    				}
    		        
    				
    				layer.tips(html, ele, {
    					tips: [1,'#f7625e'],
    					area:["400px"],
    					time:3000,
    					
    	     		 tipsMore: true
    	     		});
    			}
    		})
    	});
    	
    	//移上去查看需求情况
    	$(document).on("mouseover",".seecategory",function(){
    		layer.closeAll();
    		var id = $(this).attr("data");
    		var type = $("#customertype").val();
    		var ele = $(".seecategory"+id);
    		var html = ele.attr("catevalue");
    		if(html.length<1){
    			html="暂无资质情况";
    		}
    		layer.tips(html, ele, {
				tips: [1,'#f7625e'],
				area:["300px"],
				time:3000,
				
     		 tipsMore: true
     		});
    		
    		//需求加上证书类型
    		/*$.ajax({
    			type : "post",
    			data : {id : id},
    			url : "/customer/customercategoryandtypes",
    			dataType : "json",
    			async: false,
    			contentType: "application/x-www-form-urlencoded; charset=utf-8",
    			success : function(data){
    				var jsondata = eval(data);
    				if (jsondata.length > 0) {
    					$.each(data, function (i, item) {
        		        	html += item+"<br/>";
        		        });
    				} else {
    					if (type == 0) {
    	    				html += "该记录暂无证书信息"
    	    			} else {
    	    				html += "该记录暂无证书需求"
    	    			}
    				}
    				layer.tips(html, ele, {
    					tips: [1,'#f7625e'],
    					area:["200px"],
    					time:5000,
    					
    	     		 tipsMore: true
    	     		});
    			}
    		});*/
    	});
	//点击添加需求
    	$(".tjxqbtn").on("click",function(){
    		var size = $("input:checkbox[name='customcheckbox']:checked").length;
     		if(size!=1){
     			layer.msg("请选择一条企业记录",{icon: 0});
 				 return false;
     		}
     		var id = $("input:checkbox[name='customcheckbox']:checked").val(),
     		    qyname = $("input:checkbox[name='customcheckbox']:checked").attr("dname");
     		$("#cusid").val(id);
     		//打开弹窗
     		layer.open({
     			type:1,
     			content:$('.addxqtc'),
     			btn:['确定','取消'],
     			btnAlign:'c',
     			shadeClose:true,
     			title:qyname+"需求添加",
     			zIndex: 999,
     			area:['80%','80%'],
     			maxWidth:800,
     			yes: function(layero, index){
     				$("#tc_savecustomercategoryform").submit();
     			}
     		});
     		
    	});
    	
    	//添加需求验证
    	$("#tc_savecustomercategoryform").validate({
        	rules: {
        		zizhiType : {
	    			required:true,
	    		},
	    		count : {
	    			digits:true,
	    			required:true,
	    		},
	    		endtime : {
	    			required:true,
	    		},
	    		types : {
	    			required:true,
	    		},
	    		paperspurpose : {
	    			required:true,
	    		},
	    	},
	    	messages: {
	    		zizhiType : {
	    			required:"请选择所需证书",
	    		},
	    		count : {
	    			digits:"请输入正确的证书数量",
	    			required:"请输入所需证书数量",
	    		},
	    		endtime : {
	    			required:"请选择结束时间",
	    		},
	    		types : {
	    			required:"请选择证书性质",
	    		},
	    		paperspurpose : {
	    			required:"请选择证书用途",
	    		},
	    	},
	    	errorPlacement: function(error, element) {
				layer.tips(error.text(), element, {
					tips: [2,tipColor],
	     		 tipsMore: true
	     		});
	   		}, 
	   	 submitHandler: function(form) {
	   		var ctname =$("#zizhiType").val(); 
	   		var data = $("#tc_savecustomercategoryform").serialize();
	   		//var categoryid = $("#categoryid").val();
		 	$.ajax({
		 		type : "post",
		 		url : "/customer/savecustomercategory",
		 		data : data,
		 		dataType : "json",
		 		async : false,
		 		contentType: "application/x-www-form-urlencoded; charset=utf-8", 
		 		success : function(data){
		 			layer.msg("需求添加成功",{icon:1},function(){
		 				layer.closeAll();
		 			});
		 		}
		 	});
	      }
        });
    });
	
 

	//子页面调用 客户详情
	function infoShow(id){
		var url = "/customer/customerinfo1/c"+id;
		parent.layer.open({
			  	type:2,
	  		title:"企业详情",
	  		shadeClose:true,
	  		content: url,
	  		area:['80%','95%'],
	  		maxWidth:1000,
			});
	};	
